// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyViewerClientAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyViewerClientAttributes
//
// Purpose:
//   This class contains attributes used for viewer client
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a ViewerClientAttributes.
//
struct ViewerClientAttributesObject
{
    PyObject_HEAD
    ViewerClientAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewViewerClientAttributes(int);
std::string
PyViewerClientAttributes_ToString(const ViewerClientAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    const char *renderingType_names = "NONE, Image, Data";
    switch (atts->GetRenderingType())
    {
      case ViewerClientAttributes::None:
          snprintf(tmpStr, 1000, "%srenderingType = %sNONE  # %s\n", prefix, prefix, renderingType_names);
          str += tmpStr;
          break;
      case ViewerClientAttributes::Image:
          snprintf(tmpStr, 1000, "%srenderingType = %sImage  # %s\n", prefix, prefix, renderingType_names);
          str += tmpStr;
          break;
      case ViewerClientAttributes::Data:
          snprintf(tmpStr, 1000, "%srenderingType = %sData  # %s\n", prefix, prefix, renderingType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%sid = %d\n", prefix, atts->GetId());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%stitle = \"%s\"\n", prefix, atts->GetTitle().c_str());
    str += tmpStr;
    {   const intVector &windowIds = atts->GetWindowIds();
        snprintf(tmpStr, 1000, "%swindowIds = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < windowIds.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", windowIds[i]);
            str += tmpStr;
            if(i < windowIds.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    snprintf(tmpStr, 1000, "%simageWidth = %d\n", prefix, atts->GetImageWidth());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%simageHeight = %d\n", prefix, atts->GetImageHeight());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%simageResolutionPcnt = %g\n", prefix, atts->GetImageResolutionPcnt());
    str += tmpStr;
    if(atts->GetExternalClient())
        snprintf(tmpStr, 1000, "%sexternalClient = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sexternalClient = 0\n", prefix);
    str += tmpStr;
    {   const intVector &renderingTypes = atts->GetRenderingTypes();
        snprintf(tmpStr, 1000, "%srenderingTypes = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < renderingTypes.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", renderingTypes[i]);
            str += tmpStr;
            if(i < renderingTypes.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    return str;
}

static PyObject *
ViewerClientAttributes_Notify(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewerClientAttributes_SetRenderingType(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid renderingType value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " None";
        ss << ", Image";
        ss << ", Data";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the renderingType in the object.
    obj->data->SetRenderingType(ViewerClientAttributes::RenderType(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewerClientAttributes_GetRenderingType(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetRenderingType()));
    return retval;
}

/*static*/ PyObject *
ViewerClientAttributes_SetId(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the id in the object.
    obj->data->SetId(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewerClientAttributes_GetId(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetId()));
    return retval;
}

/*static*/ PyObject *
ViewerClientAttributes_SetTitle(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the title in the object.
    obj->data->SetTitle(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewerClientAttributes_GetTitle(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetTitle().c_str());
    return retval;
}

/*static*/ PyObject *
ViewerClientAttributes_SetWindowIds(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetWindowIds() = vec;
    // Mark the windowIds in the object as modified.
    obj->data->SelectWindowIds();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewerClientAttributes_GetWindowIds(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the windowIds.
    const intVector &windowIds = obj->data->GetWindowIds();
    PyObject *retval = PyTuple_New(windowIds.size());
    for(size_t i = 0; i < windowIds.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(windowIds[i])));
    return retval;
}

/*static*/ PyObject *
ViewerClientAttributes_SetImageWidth(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the imageWidth in the object.
    obj->data->SetImageWidth(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewerClientAttributes_GetImageWidth(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetImageWidth()));
    return retval;
}

/*static*/ PyObject *
ViewerClientAttributes_SetImageHeight(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the imageHeight in the object.
    obj->data->SetImageHeight(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewerClientAttributes_GetImageHeight(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetImageHeight()));
    return retval;
}

/*static*/ PyObject *
ViewerClientAttributes_SetImageResolutionPcnt(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the imageResolutionPcnt in the object.
    obj->data->SetImageResolutionPcnt(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewerClientAttributes_GetImageResolutionPcnt(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetImageResolutionPcnt());
    return retval;
}

/*static*/ PyObject *
ViewerClientAttributes_SetExternalClient(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the externalClient in the object.
    obj->data->SetExternalClient(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewerClientAttributes_GetExternalClient(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetExternalClient()?1L:0L);
    return retval;
}

/*static*/ PyObject *
ViewerClientAttributes_SetRenderingTypes(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetRenderingTypes() = vec;
    // Mark the renderingTypes in the object as modified.
    obj->data->SelectRenderingTypes();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewerClientAttributes_GetRenderingTypes(PyObject *self, PyObject *args)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the renderingTypes.
    const intVector &renderingTypes = obj->data->GetRenderingTypes();
    PyObject *retval = PyTuple_New(renderingTypes.size());
    for(size_t i = 0; i < renderingTypes.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(renderingTypes[i])));
    return retval;
}



PyMethodDef PyViewerClientAttributes_methods[VIEWERCLIENTATTRIBUTES_NMETH] = {
    {"Notify", ViewerClientAttributes_Notify, METH_VARARGS},
    {"SetRenderingType", ViewerClientAttributes_SetRenderingType, METH_VARARGS},
    {"GetRenderingType", ViewerClientAttributes_GetRenderingType, METH_VARARGS},
    {"SetId", ViewerClientAttributes_SetId, METH_VARARGS},
    {"GetId", ViewerClientAttributes_GetId, METH_VARARGS},
    {"SetTitle", ViewerClientAttributes_SetTitle, METH_VARARGS},
    {"GetTitle", ViewerClientAttributes_GetTitle, METH_VARARGS},
    {"SetWindowIds", ViewerClientAttributes_SetWindowIds, METH_VARARGS},
    {"GetWindowIds", ViewerClientAttributes_GetWindowIds, METH_VARARGS},
    {"SetImageWidth", ViewerClientAttributes_SetImageWidth, METH_VARARGS},
    {"GetImageWidth", ViewerClientAttributes_GetImageWidth, METH_VARARGS},
    {"SetImageHeight", ViewerClientAttributes_SetImageHeight, METH_VARARGS},
    {"GetImageHeight", ViewerClientAttributes_GetImageHeight, METH_VARARGS},
    {"SetImageResolutionPcnt", ViewerClientAttributes_SetImageResolutionPcnt, METH_VARARGS},
    {"GetImageResolutionPcnt", ViewerClientAttributes_GetImageResolutionPcnt, METH_VARARGS},
    {"SetExternalClient", ViewerClientAttributes_SetExternalClient, METH_VARARGS},
    {"GetExternalClient", ViewerClientAttributes_GetExternalClient, METH_VARARGS},
    {"SetRenderingTypes", ViewerClientAttributes_SetRenderingTypes, METH_VARARGS},
    {"GetRenderingTypes", ViewerClientAttributes_GetRenderingTypes, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
ViewerClientAttributes_dealloc(PyObject *v)
{
   ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *ViewerClientAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyViewerClientAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "renderingType") == 0)
        return ViewerClientAttributes_GetRenderingType(self, NULL);
    if(strcmp(name, "None") == 0)
        return PyInt_FromLong(long(ViewerClientAttributes::None));
    if(strcmp(name, "NONE") == 0)
        return PyInt_FromLong(long(ViewerClientAttributes::None));
    if(strcmp(name, "Image") == 0)
        return PyInt_FromLong(long(ViewerClientAttributes::Image));
    if(strcmp(name, "Data") == 0)
        return PyInt_FromLong(long(ViewerClientAttributes::Data));

    if(strcmp(name, "id") == 0)
        return ViewerClientAttributes_GetId(self, NULL);
    if(strcmp(name, "title") == 0)
        return ViewerClientAttributes_GetTitle(self, NULL);
    if(strcmp(name, "windowIds") == 0)
        return ViewerClientAttributes_GetWindowIds(self, NULL);
    if(strcmp(name, "imageWidth") == 0)
        return ViewerClientAttributes_GetImageWidth(self, NULL);
    if(strcmp(name, "imageHeight") == 0)
        return ViewerClientAttributes_GetImageHeight(self, NULL);
    if(strcmp(name, "imageResolutionPcnt") == 0)
        return ViewerClientAttributes_GetImageResolutionPcnt(self, NULL);
    if(strcmp(name, "externalClient") == 0)
        return ViewerClientAttributes_GetExternalClient(self, NULL);
    if(strcmp(name, "renderingTypes") == 0)
        return ViewerClientAttributes_GetRenderingTypes(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyViewerClientAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyViewerClientAttributes_methods[i].ml_name),
                PyString_FromString(PyViewerClientAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyViewerClientAttributes_methods, self, name);
}

int
PyViewerClientAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "renderingType") == 0)
        obj = ViewerClientAttributes_SetRenderingType(self, args);
    else if(strcmp(name, "id") == 0)
        obj = ViewerClientAttributes_SetId(self, args);
    else if(strcmp(name, "title") == 0)
        obj = ViewerClientAttributes_SetTitle(self, args);
    else if(strcmp(name, "windowIds") == 0)
        obj = ViewerClientAttributes_SetWindowIds(self, args);
    else if(strcmp(name, "imageWidth") == 0)
        obj = ViewerClientAttributes_SetImageWidth(self, args);
    else if(strcmp(name, "imageHeight") == 0)
        obj = ViewerClientAttributes_SetImageHeight(self, args);
    else if(strcmp(name, "imageResolutionPcnt") == 0)
        obj = ViewerClientAttributes_SetImageResolutionPcnt(self, args);
    else if(strcmp(name, "externalClient") == 0)
        obj = ViewerClientAttributes_SetExternalClient(self, args);
    else if(strcmp(name, "renderingTypes") == 0)
        obj = ViewerClientAttributes_SetRenderingTypes(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
ViewerClientAttributes_print(PyObject *v, FILE *fp, int flags)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)v;
    fprintf(fp, "%s", PyViewerClientAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
ViewerClientAttributes_str(PyObject *v)
{
    ViewerClientAttributesObject *obj = (ViewerClientAttributesObject *)v;
    return PyString_FromString(PyViewerClientAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *ViewerClientAttributes_Purpose = "This class contains attributes used for viewer client";
#else
static char *ViewerClientAttributes_Purpose = "This class contains attributes used for viewer client";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(ViewerClientAttributesType,         \
                  "ViewerClientAttributes",           \
                  ViewerClientAttributesObject,       \
                  ViewerClientAttributes_dealloc,     \
                  ViewerClientAttributes_print,       \
                  PyViewerClientAttributes_getattr,   \
                  PyViewerClientAttributes_setattr,   \
                  ViewerClientAttributes_str,         \
                  ViewerClientAttributes_Purpose,     \
                  ViewerClientAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
ViewerClientAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &ViewerClientAttributesType
         || Py_TYPE(other) != &ViewerClientAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    ViewerClientAttributes *a = ((ViewerClientAttributesObject *)self)->data;
    ViewerClientAttributes *b = ((ViewerClientAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static ViewerClientAttributes *defaultAtts = 0;
static ViewerClientAttributes *currentAtts = 0;

static PyObject *
NewViewerClientAttributes(int useCurrent)
{
    ViewerClientAttributesObject *newObject;
    newObject = PyObject_NEW(ViewerClientAttributesObject, &ViewerClientAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new ViewerClientAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new ViewerClientAttributes(*defaultAtts);
    else
        newObject->data = new ViewerClientAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapViewerClientAttributes(const ViewerClientAttributes *attr)
{
    ViewerClientAttributesObject *newObject;
    newObject = PyObject_NEW(ViewerClientAttributesObject, &ViewerClientAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (ViewerClientAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
ViewerClientAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewViewerClientAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef ViewerClientAttributesMethods[] = {
    {"ViewerClientAttributes", ViewerClientAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *ViewerClientAttributesObserver = 0;

std::string
PyViewerClientAttributes_GetLogString()
{
    std::string s("ViewerClientAtts = ViewerClientAttributes()\n");
    if(currentAtts != 0)
        s += PyViewerClientAttributes_ToString(currentAtts, "ViewerClientAtts.", true);
    return s;
}

static void
PyViewerClientAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("ViewerClientAtts = ViewerClientAttributes()\n");
        s += PyViewerClientAttributes_ToString(currentAtts, "ViewerClientAtts.", true);
        cb(s);
    }
}

void
PyViewerClientAttributes_StartUp(ViewerClientAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyViewerClientAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(ViewerClientAttributesObserver == 0)
    {
        ViewerClientAttributesObserver = new ObserverToCallback(subj,
            PyViewerClientAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyViewerClientAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete ViewerClientAttributesObserver;
    ViewerClientAttributesObserver = 0;
}

PyMethodDef *
PyViewerClientAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return ViewerClientAttributesMethods;
}

bool
PyViewerClientAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &ViewerClientAttributesType);
}

ViewerClientAttributes *
PyViewerClientAttributes_FromPyObject(PyObject *obj)
{
    ViewerClientAttributesObject *obj2 = (ViewerClientAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyViewerClientAttributes_New()
{
    return NewViewerClientAttributes(0);
}

PyObject *
PyViewerClientAttributes_Wrap(const ViewerClientAttributes *attr)
{
    return WrapViewerClientAttributes(attr);
}

void
PyViewerClientAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    ViewerClientAttributesObject *obj2 = (ViewerClientAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyViewerClientAttributes_SetDefaults(const ViewerClientAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new ViewerClientAttributes(*atts);
}

